_package("gt.page");

_import("caf.ui.Button");
_import("caf.ui.TabPanel");
_import("caf.ui.Page");

_class("HomePage", Page, function(){

	this._init = function(){
		_super._init.call(this);
	};
	this.create = function(parent){
		var obj = this.createTplElement(parent, "home.xml");
		this.init(obj);
		return obj;
	};
	this.init = function(){
		_super.init.apply(this, arguments);
		this.initComponents();
		this.initActionElements();
		var self = this;
		$("#gsSub").click (function(){
			self.do_translate();
		});
		$("#toDict").click(function(){
			self.do_toDict();
		});
		$(".change1").click(function(){
			var from = $("#from").val();
			$("#from").val($("#to").val());
			$("#to").val(from);
		});
	};
	this.dispose = function(){
		_super.dispose.apply(this);
	};
	
	this.do_translate = function(){
		var appId = "44091D72CBEA0C589063B98766F54673676CC50E";
		var from = $("#from").val();
		var to = $("#to").val();
		var value = $("#quest").val();
		//alert($("#s").val());
		if(value!=""){
			var url = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=" + appId + "&from=" + from + "&to=" + to + "&text=" + value + "&oncomplete=?";
			/*$.getJSON(url,{},function(data){
				$("#t").html(data);
			});*/
			$.ajax({
				type:"get",
				url:url,
				dataType:"jsonp",
				success : function(data){
					$("#wait").hide();
					$("#t").html(data);
					$("#quest").blur();
					//$("#from").focus();
				},
				beforeSend : function(){
					$("#wait").html('<img src="res/images/wait.png"/>请稍候');
					$("#wait").show();
					
				},
				error : function(){
					$("#wait").html('出错了,请重试');
					$("#wait").show();
				}
			});
		}
		
	};
	this.do_toDict = function(){
		this._app.navPage("dict",{"from" : this._pid});
	}
});